package com.septimus.portal.service;

import org.apache.log4j.Logger;

import javax.ejb.Stateless;
import javax.enterprise.event.Event;
import javax.inject.Inject;
import javax.persistence.EntityManager;

import com.septimus.portal.model.Configuration;

@Stateless
public class ConfigRegistration {
	@Inject
	private Logger log;

	@Inject
	private EntityManager em;

	@Inject
	private Event<Configuration> configEventSrc;

	public Configuration register(Configuration config) throws Exception {
		log.info("\n\nRegistering new configuration");
		Configuration conf = em.merge(config);
		configEventSrc.fire(config);
		return conf;
	}

	public Configuration load(Long index) {
		log.info("\n\nLoading configuration");
		return em.find(Configuration.class, index);
	}
}
